const jwtUtil = require('../utils/jwtUtils')

module.exports = class user_dao extends require('../model/user_model') {
	static async getAllData(req, resq) {
		let data = await this.findAllList('')
		resq.send({data:data})
	}

	static async Login(req ,resq) {
		let body = req.body
		// console.log(body);
		let loginData = await this.login(body.username, body.password)
		// console.log(loginData[0]);
		// resq.send({loginData})
		if(loginData.length != 0) {
			let token = jwtUtil.sign({
				id:loginData[0].id,
				name: loginData[0].name,
				sex: loginData[0].sex,
				age:loginData[0].age,
				role: loginData[0].role,
				roleid: loginData[0].roleid,
				password: loginData[0].password
			},'key',3600)
			resq.send({message: '登录成功！', status:200 ,token})
		} else resq.status(500).send('用户名或密码有误！')
	}
}